<template>
    <div>
        <div class="tab-back">
            <a class="left" @click="toback()"></a>
            <div class="title">补时/停更/延时</div>
            <div class="right"></div>
        </div>
        <div class="box-r4" style="padding: 0px 15px;">
            <div class="tips_title">补时/停更/延时</div>
            <div class="selectbox">
                <select dir="ltr" v-model="bushiday">
                    <option :value="0">请选择天数</option>
                    <option :key="item" :value="item" v-for="item in numberList">{{item}}{{item!='选择自定义时间'?'天':''}}</option>
                </select>
            </div>
        </div>
        <div class="tips">
            <p>当前包时中人数：{{number}}人</p>
            <div>确认提交后，正在包时中的客户，获得以上相应的时间延长</div>
        </div>
        <van-dialog v-model="numShow" title="请在下方输入自定义天数" @confirm="changeNum">
            <div class="dialog-box">
                <van-field v-model="dayNumber" placeholder="请输入天数" type="number"/>
            </div>
        </van-dialog>
        <input type="button" class="red_btn btn-bottom" value="确认" @click="comfirm()">
    </div>
</template>

<script>
    var timer;
    export default {
        name: "",
        data(){
            return {
                materialsid:"",
                bushiday: 0,
                number:0,
                dayNumber: '',
                numShow: false,
                numberList: []
            }
        },
        mounted(){
            this.materialsid=this.$route.query.id;
            this.init();
            this.getmatebuynumber();
        },
        watch:{
            bushiday(val){
                if(val == '选择自定义时间') return this.numShow = true;
            }
        },
        methods:{
            /* 修改数据 */
            changeNum(){
                this.bushiday = this.dayNumber;
                console.log(this.bushiday);
                console.log(this.dayNumber);
            },
            /* 初始化数组 */
            init(){
                this.numberList.push('选择自定义时间');
                for(let i = 1; i < 365; i++){
                    this.numberList.push(i);
                }
            },
            getmatebuynumber(){
                var that=this;

                that.request1.post1({
                    url: that.Url + "api/Materials/matebuynumber",
                    params: {   materialsid:that.materialsid},
                    success: function (res) {
                        if (res.data.code == 1) {
                            that.number=res.data.data.number;

                        } else {
                            alert(res.data.msg)
                        }
                    },
                    fail: function (error) {
                        alert(error.data.msg)
                    }
                })
            },
            comfirm(){
                var that=this;

                if(that.bushiday<1){
                    that.$toast("请选择延时天数")
                    return false;
                }
                that.request1.post1({
                    url: that.Url + "api/Materials/yanshiSave",
                    params: {   materialsid:that.materialsid, yanshidays:that.bushiday},
                    success: function (res) {
                        if (res.data.code == 1) {
                            that.$toast.success("延时成功");
                            timer=setTimeout(function () {
                                that.$router.go(-1)
                            },2000)
                        } else {
                            alert(res.data.msg)
                        }
                    },
                    fail: function (error) {
                        alert(error.data.msg)
                    }
                })
            },
            toback(){
                this.$router.go(-1);
            }
        }
    }
</script>

<style scoped>
    .dialog-box{
        padding: 10px 30px;
    }

    .tab-back {
        height: 44px;
        background: #fc5d4d;
        display: -webkit-box;
    }
    .tab-back .left {
        width: 44px;
        display: block;
        height: 44px;
        background: url() no-repeat 50%;
        background-size: 9px 16px;
    }
    .tab-back .title {
        -webkit-box-flex: 1;
        font-size: 15px;
        color: #fff;
        font-weight: 700;
        text-align: center;
        line-height: 44px;
    }
    .tab-back .right {
        width: 44px;
        height: 44px;
    }
    .box-r4, .red_btn {
        border-radius: 4px;
    }
    .box-r4 {
        display: block;
        background: #fff;
        margin: 7px 10px 0;
        padding: 0 15px;
        overflow: hidden;
    }
    .tips_title {
        font-size: 14px;
        font-weight: 700;
        color: #000;
        display: block;
        line-height: 14px;
        padding-top: 20px;
        padding-bottom: 10px;
    }
    button, input, optgroup, select, textarea {
        font-family: sans-serif;
        font-size: 100%;
        line-height: 1.15;
        margin: 0;
    }

    .red_ft {
        color: #fc5d4d !important;
    }
    .input_text {
        height: 36px;
        border-radius: 4px;
        font-size: 13px;
        border: 1px solid #e5e5e5;
        padding: 0 4%;
        background: #f9f9fb;
        width: 92%;
        display: block;
        margin-bottom: 15px;
    }
    .red_btn {
        background: #fc5d4d;
        color: #fff;
        font-size: 14px;
        text-align: center;
        height: 40px;
        line-height: 40px;
        width: 90%;
        margin: 20px 5% 100px;
        box-shadow: 0 5px 10px #f6a59f;
    }
    .box-r4, .red_btn {
        border-radius: 4px;
    }
    .btn-bottom {
        position: fixed;
        bottom: 20px;
        margin-bottom: 0 !important;
    }
    .selectbox{
        height: 36px;
        border-radius: 4px;
        font-size: 13px;
        border: 1px solid #e5e5e5;
        padding: 0 4%;
        background: #f9f9fb;
        width: 92%;
        display: block;
        margin-bottom: 15px;
    }
    .selectbox select {
        width: 100%;
        padding-left: 25px;
        text-align: right;
        border: none;
        height: 40px;
        background: url() no-repeat left ;
        background-size: 10px;
        appearance: none;
        -moz-appearance: none;
        -webkit-appearance: none;
        -ms-appearance: none;
    }
    input::-webkit-calendar-picker-indicator{
        display: none;
        -webkit-appearance: none !important;
    }
    input{
        -webkit-appearance: none !important;
    }
    .tips{
        padding: 10px 15px;
        line-height: 24px;
        font-size: 12px;
    }
    .tips p{
        color: #4482e4
    }
</style>